//
//  SinaTabBar.swift
//  weibo
//
//  Created by sirius on 15/12/30.
//  Copyright © 2015年 sirius. All rights reserved.
//

import UIKit

class SinaTabBar: UITabBar {
    
    
    //添加Btn 设置frame
    
    
    override init(frame: CGRect) {//这个是View的指定构造函数
        super.init(frame: frame)
        //添加子控件
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
     //MARK: 添加子控件
    private func setupUI(){
        addSubview(composeButton)
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        //设置frame
        composeButton.center = CGPointMake(bounds.width * 0.5, bounds.height * 0.5)
        //UITabBarButton--   是swift 私有的子类
        //遍历subviews,得到所有的子类,继而判断出UITabBarButton，单一改变frame
        var index = 0
        for subview in subviews{
            printLog(subview)
            let width = bounds.width * 0.2
//
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!)
            {
                printLog("找到")
                subview.frame = CGRectMake(CGFloat(index) * width, bounds.origin.y, width, bounds.height)
                index++
                if index == 2{
                    index++
                }
                    }
            
        }
     
    }
    //MARK: 懒加载一个Button 
    lazy var composeButton: UIButton = {
        let button = UIButton(type: UIButtonType.Custom)
        //设置属性
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        //设置宽高
        button.sizeToFit()
        
        return button
    }()


}
